Skip to content

Comments

feats(fetchOptions):#206

Merged
danybeltran merged 1 commit intomasterfrom
feats/fetchOptions
Jul 25, 2025
Merged

feats(fetchOptions):#206
danybeltran merged 1 commit intomasterfrom
feats/fetchOptions

Conversation

@danybeltran
Copy link
Member

Adds fetchOptions fn.

Example usage:

import useFetch, { fetchOptions } from "http-react"

// TS
type TodoType = {
  id: number;
  title: string;
  userId: number;
  completed: boolean;
};

const todosFetch = fetchOptions<TodoType[]>({
  default: [], // initial data
  fetcher: () => fetch("https://jsonplaceholder.typicode.com/todos"),
});


// Use that options object
function Todos() {
  const { data, loading, refresh } = useFetch(todosFetch);

  return (
    <div>
      <h2 className="text-2xl font-semibold">Todos</h2>
      <button onClick={refresh}>Refresh todos...</button>
      {data.map((todo) => (
        <div key={"todo" + todo.id}>{todo.title}</div>
      ))}
    </div>
  );
}

Adds fetchOptions fn
@danybeltran danybeltran merged commit 3597b63 into master Jul 25, 2025
2 checks passed
@danybeltran danybeltran deleted the feats/fetchOptions branch July 25, 2025 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant